package com.suray.wcs.service.thread;

import com.suray.basic.wcs.utils.LoggerType;
import com.suray.basic.wcs.utils.LoggerUtil;
import com.suray.basic.wcs.utils.ModuleType;
import com.suray.basic.wcs.utils.WcsFuncUtil;
import com.suray.basic.wcs.utils.thread.BaseThread;
import com.suray.wcs.res.enums.RgvStatus;
import com.suray.wcs.res.enums.RgvType;
import com.suray.wcs.service.pojo.Rgv;
import com.suray.wcs.service.rescontact.ToRes;

public class RgvInitThread extends BaseThread {

    private Rgv rgv;

    public RgvInitThread(Rgv rgv) {
        super(rgv.getRgvName() + " 初始化", 0, ModuleType.DEFAULT);
        this.rgv = rgv;
    }

    @Override
    public synchronized void start() {
        if (rgv.checkRgvType(RgvType.FIVE_POINT_FOUR_TL) || rgv.checkRgvType(RgvType.FIVE_POINT_FOUR_TS)) {
            super.start();
        }
    }

    @Override
    protected void process() {
        try {
            initRgv();
            endThread();
            rgv.setInitOk(true);
        } catch (Exception e) {
        }

        if (!rgv.isInitOk() && rgv.getRgvStatus() != RgvStatus.OFF_LINE) {
            try {
                initRgv();
                rgv.setInitOk(true);
            } catch (Exception e) {
                LoggerUtil.info(ModuleType.RES_20_RGV, LoggerType.ERROR, null, rgv.getRgvName(),
                        "获取小车版本失败", this.getClass());
            }

            endThread();
        }
    }

    /**
     * 初始化小车
     */
    private void initRgv() {
        ToRes toRes = ToRes.getInstance(rgv);
        toRes.getResVersion(null);
    }
}
